﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;


namespace Nivdal
{
    public partial class ComparePlayers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // security part
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");

            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");

            // this page is for premium users only
            if (!ou.IsPremium)
                Response.Redirect("~/GeneralMessage.aspx?MessageString=gfkkjFSDei3w7lzTD");

            // end of security part
            ////////////////////////////////////////////////////////////////////

            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.ComparePlayers_PageTitle;
            if (!IsPostBack)
            {
                PlayerCompareDataSourse.SelectParameters.Add("UserId", ou.UserId);
            }
            if (CompareGridview.Rows.Count > 0)
            {
                CompareGridview.UseAccessibleHeader = true;
                CompareGridview.HeaderRow.TableSection = TableRowSection.TableHeader;
            }

            ScriptManager.RegisterStartupScript(this, GetType(), "SortGrid", string.Format("$(function(){{$('#{0}').tablesorter(); }});", CompareGridview.ClientID), true);

        }


        //protected void DeleteSelected(object sender, EventArgs e)
        //{
        //    string CompareId;
        //    bool Checked;
        //    GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
        //    foreach (GridViewRow row in CompareGridview.Rows)
        //    {
        //        Checked = (row.FindControl("DeleteCheckBox") as CheckBox).Checked;
        //        if (Checked)
        //        {
        //            CompareId = (row.FindControl("CompareIdHiddenField") as HiddenField).Value;
        //            GND.ExecNivdalSQL("CompareId", "Nivdal_DeletePlayerCompare", CompareId);
        //        }
        //    }
        //    Response.Redirect("~/ComparePlayers.aspx");
        //}

        //protected void DeleteRow(object sender, GridViewCommandEventArgs e)
        //{
        //    if (e.CommandName == "DeletePlayer")
        //    {
        //        GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
        //        GND.ExecNivdalSQL("CompareId", "Nivdal_DeletePlayerCompare", e.CommandArgument);
        //    }
        //    PlayerCompareDataSourse.DataBind();
        //    CompareGridview.DataBind();
        //}

        protected void Page_Unload(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            // delete all previous selections
            GND.ExecNivdalSQL("UserId", "Nivdal_InitPlayerCompareForUser", ou.UserId);
        }


        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }


    }
}